package com.shushan.util;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import com.shushan.base.BaseActivity;
import com.shushan.shushanbao.BuildConfig;

import java.util.ArrayList;
import java.util.List;


/**
 * @ClassName: VideoUtils
 * @Desciption: 视频工具类
 * @author: yichaohua
 * @date: 2018-02-03
 */
public class VideoUtils {

    public static void playVideo(BaseActivity context, String url){
        if(TextUtils.isEmpty(url)){
            return;
        }

        String videoUrl;
        if(ImageUtils.isAbsoluteUrl(url)){
            videoUrl = url;
        }else {
            videoUrl = BuildConfig.imgBaseUrl + url;
        }

        Uri uri = Uri.parse(videoUrl);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/mp4");

        context.setAllowBack(true);
        try {
            context.startActivity(intent);
        }catch (Exception e){
            context.setAllowBack(false);
            ToastUtils.showToast(context,"没有默认播放器");
        }

    }


    public static boolean containOutlineId(String detailId,String outlineDetailIds){
        if(TextUtils.isEmpty(detailId) || TextUtils.isEmpty(outlineDetailIds)){
            return false;
        }

        String [] detailIdArray = outlineDetailIds.split(",");
        for(String outlineId : detailIdArray){
            if(outlineId.equals(detailId) /*&& !containOutlineBean(outlineId,videoPointList)*/){
                return true;
            }
        }

        return false;
    }

}
